package com.mall.business.controller;


import java.util.Arrays;
import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.mall.common.annotation.Log;
import com.mall.common.core.controller.BaseController;
import com.mall.common.core.domain.AjaxResult;
import com.mall.common.enums.BusinessType;
import com.mall.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.mall.business.domain.TCart;
import com.mall.business.service.ITCartService;
import com.mall.common.core.page.TableDataInfo;

/**
 * 购物车信息Controller
 *
 * @author ruoyi
 * @date 2025-03-30
 */
@RestController
@RequestMapping("/business/cart")
public class TCartController extends BaseController {
    @Autowired
    private ITCartService tCartService;

    /**
     * 查询购物车信息列表
     */
//@RequiresPermissions("business:cart:list")
    @GetMapping("/list")
    public TableDataInfo list(TCart tCart) {
        startPage();
        List<TCart> list = tCartService.selectTCartList(tCart);
        return getDataTable(list);
    }

    /**
     * 导出购物车信息列表
     */
    //@RequiresPermissions("business:cart:export")
    @Log(title = "购物车信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TCart tCart) {
        List<TCart> list = tCartService.selectTCartList(tCart);
        ExcelUtil<TCart> util = new ExcelUtil<TCart>(TCart.class);
        util.exportExcel(response, list, "购物车信息数据");
    }

    /**
     * 获取购物车信息详细信息
     */
    //@RequiresPermissions("business:cart:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return AjaxResult.success(tCartService.getById(id));
    }

    /**
     * 新增购物车信息
     */
    //@RequiresPermissions("business:cart:add")
    @Log(title = "购物车信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TCart tCart) {
        return toAjax(tCartService.save(tCart));
    }

    /**
     * 修改购物车信息
     */
    //@RequiresPermissions("business:cart:edit")
    @Log(title = "购物车信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TCart tCart) {
        return toAjax(tCartService.updateById(tCart));
    }

    /**
     * 删除购物车信息
     */
    //@RequiresPermissions("business:cart:remove")
    @Log(title = "购物车信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(tCartService.removeByIds(Arrays.asList(ids)));
    }
}
